package org.mybatis3.demo1;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.mybatis3.demo1.dao.UserMapper;
import org.mybatis3.demo1.pojo.User;

import java.io.InputStream;
import java.util.List;

public class Test4 {
    public static void main(String[] args) {
        String resource="mybatis-config.xml";
        InputStream is=null;
        SqlSession sqlSession=null;
        try{
            is= Resources.getResourceAsStream(resource);

            SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(is);
            sqlSession=factory.openSession();

//            User user= sqlSession.selectOne("org.mybatis3.demo1.dao.UserMapper.getOneUser",1);
//            System.out.println(user.getUserName());

            List<User> userList=sqlSession.getMapper(UserMapper.class).getUserList();
            for(int i=0;i<userList.size();i++){
                System.out.println("用户名："+userList.get(i).getUserName());
            }
        }catch(Exception e) {
            e.printStackTrace();
        }
    }
}
